package com.kf.xinxi.controller;

import java.util.List;

import com.kf.common.annotation.Log;
import com.kf.common.core.controller.BaseController;
import com.kf.common.core.domain.AjaxResult;
import com.kf.common.core.page.TableDataInfo;
import com.kf.common.enums.BusinessType;
import com.kf.common.utils.poi.ExcelUtil;
import com.kf.xinxi.domain.Xuexiao;
import com.kf.xinxi.service.IXuexiaoService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * 学校信息Controller
 *
 * @author zsd
 * @date 2021-04-16
 */
@RestController
@RequestMapping("/xinxi/xuexiao")
public class XuexiaoController extends BaseController
{
    @Autowired
    private IXuexiaoService xuexiaoService;

    /**
     * 查询学校信息列表
     */
    @PreAuthorize("@ss.hasPermi('xinxi:xuexiao:list')")
    @GetMapping("/list")
    public TableDataInfo list(Xuexiao xuexiao)
    {
        startPage();
        List<Xuexiao> list = xuexiaoService.selectXuexiaoList(xuexiao);
        return getDataTable(list);
    }

    /**
     * 导出学校信息列表
     */
    @PreAuthorize("@ss.hasPermi('xinxi:xuexiao:export')")
    @Log(title = "学校信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Xuexiao xuexiao)
    {
        List<Xuexiao> list = xuexiaoService.selectXuexiaoList(xuexiao);
        ExcelUtil<Xuexiao> util = new ExcelUtil<Xuexiao>(Xuexiao.class);
        return util.exportExcel(list, "xuexiao");
    }

    /**
    * 导入学校信息列表
    */
    @PreAuthorize("@ss.hasPermi('xinxi:xuexiao:import')")
    @PostMapping("/importData")
    @ResponseBody
    @Log(title = "学校信息", businessType = BusinessType.IMPORT)
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<Xuexiao> util = new ExcelUtil<Xuexiao>(Xuexiao.class);
        List<Xuexiao> list = util.importExcel(file.getInputStream());
        String message = xuexiaoService.importData(list, updateSupport);
        return AjaxResult.success(message);
    }

    @GetMapping("/importTemplate")
    public AjaxResult importTemplate()
    {
        ExcelUtil<Xuexiao> util = new ExcelUtil<Xuexiao>(Xuexiao.class);
        return util.importTemplateExcel("用户数据");
    }

    /**
     * 获取学校信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('xinxi:xuexiao:query')")
    @GetMapping(value = "/{xid}")
    public AjaxResult getInfo(@PathVariable("xid") Long xid)
    {
        return AjaxResult.success(xuexiaoService.selectXuexiaoById(xid));
    }

    /**
     * 新增学校信息
     */
    @PreAuthorize("@ss.hasPermi('xinxi:xuexiao:add')")
    @Log(title = "学校信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Xuexiao xuexiao)
    {
        return toAjax(xuexiaoService.insertXuexiao(xuexiao));
    }

    /**
     * 修改学校信息
     */
    @PreAuthorize("@ss.hasPermi('xinxi:xuexiao:edit')")
    @Log(title = "学校信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Xuexiao xuexiao)
    {
        return toAjax(xuexiaoService.updateXuexiao(xuexiao));
    }

    /**
     * 删除学校信息
     */
    @PreAuthorize("@ss.hasPermi('xinxi:xuexiao:remove')")
    @Log(title = "学校信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{xids}")
    public AjaxResult remove(@PathVariable Long[] xids)
    {
        return toAjax(xuexiaoService.deleteXuexiaoByIds(xids));
    }
}
